package com.taiji.dicom4cloud.smart.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.util.StringUtil;
import com.taiji.dicom4cloud.common.core.utils.CommonUtils;
import com.taiji.dicom4cloud.common.core.utils.R;
import com.taiji.dicom4cloud.common.log.annotation.SnowLog;
import com.taiji.dicom4cloud.smart.model.entity.AlarmEquipment;
import com.taiji.dicom4cloud.smart.model.entity.Camera;
import com.taiji.dicom4cloud.smart.model.entity.RfidEquipment;
import com.taiji.dicom4cloud.smart.service.CameraEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 摄像头设备
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/camera" )
@Api(value = "camera", tags = "管理")
public class CameraEquipmentController {



    private final CameraEquipmentService cameraEquipmentService;


    /**
     * 查询摄像头设备
     * @param page
     * @param camera
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getCameraEquipmentPage(Page page, Camera camera) {
        return R.ok(cameraEquipmentService.getCameraEquipmentPage(page,camera));
    }

    @ApiOperation(value = "查询所有设备列表", notes = "查询所有设备列表")
    @GetMapping("/all" )
    public R getRfidEquipmentAll(String orgId){
        return R.ok(cameraEquipmentService.list(
                Wrappers.<Camera>lambdaQuery()
                        .eq(StringUtil.isNotEmpty(orgId)&&!orgId.equals("-1"),
                                Camera::getOrgId,orgId)
                        .eq(Camera::getDelFalg,"0")));
    }

    /**
     * 查询摄像头信息
     * @param deviceId
     * @return
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{deviceId}" )
    public R getById(@PathVariable("deviceId" ) String deviceId) {
        return R.ok(cameraEquipmentService.getOne(Wrappers.<Camera>lambdaQuery().eq(Camera::getDeviceId,deviceId)));
    }

    /**
     * 新增摄像头
     * @param camera
     * @return
     */
    @ApiOperation(value = "新增", notes = "新增")
    @SnowLog("新增" )
    @PostMapping
    public R save(@RequestBody Camera camera) {
        camera.setCameraEquipmentId(CommonUtils.getUUID());
        return R.ok(cameraEquipmentService.save(camera));
    }

    /**
     * 修改
     * @param camera
     * @return
     */
    @ApiOperation(value = "修改", notes = "修改")
    @SnowLog("修改" )
    @PutMapping
    public R updateById(@RequestBody Camera camera) {
        return R.ok(cameraEquipmentService.updateById(camera));
    }
}
